package com.lincoln.entity.role;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.lincoln.entity.BaseEntity;
import com.lincoln.entity.permission.DbPermission;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.List;

/**
 * 等级(这里通过数据库关联具体权限)
 */
@Data
@Entity(name = "role")
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})//转json忽略参数
public class DbRole extends BaseEntity {
    //等级名
    @Column(name = "name", columnDefinition = "varchar(200)", length = 200, nullable = false)
    String name;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "permission_role", joinColumns = {
            @JoinColumn(name = "role_id", referencedColumnName = "id")}, inverseJoinColumns = {
            @JoinColumn(name = "permission_id", referencedColumnName = "id")})
    private List<DbPermission> permissions;
}
